package com.chenjia.proto.converter.demo;

import com.chenjia.proto.converter.MessageConverter;
import com.chenjia.proto.converter.demo.message.Merchant;
import com.chenjia.proto.converter.demo.message.RecommendGoods;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class Main {
    private static final MessageConverter converter = MessageConverter.reflect();
    private static final MessageConverter converter2 = MessageConverter.reflectAsm();

    public static void main(String[] args) {
//        final Goods goods = toPojo();
//        System.out.println("pojo = " + goods);

        final RecommendGoods recommendGoods = toMessage();
        System.out.println("message = " + recommendGoods);
    }

    public static RecommendGoods toMessage() {
        final Goods pojo = Goods.of();
        return converter.toMessage(RecommendGoods.class, pojo);
    }

    public static Goods toPojo() {
        Merchant merchant = Merchant.newBuilder().setId(233).setName("taobao").setStar(5).build();
        Map<Integer, Merchant> merchantMap = new HashMap<>(4);
        merchantMap.put(1, Merchant.newBuilder().setId(234).setName("taobao4").setStar(2).build());
        merchantMap.put(2, Merchant.newBuilder().setId(235).setName("taobao5").setStar(1).build());
        List<Integer> counts = new ArrayList<>(4);
        counts.add(2);
        counts.add(1);
        counts.add(5);
        counts.add(3);
        RecommendGoods message = RecommendGoods.newBuilder()
                .setGoodsId(92879182)
                .setBrandId(3928832)
                .setCatId(1.1111F)
                .setFirstCatId(9849832)
                .setGoodsSn("sn3827398")
                .setMerchantId(2333)
                .setShippingFee(false)
                .setShopPrice(2.22323)
                .setMerchant(merchant)
                .putAllMerchants(merchantMap)
                .addAllCounts(counts)
                .build();
        return converter.toPojo(Goods.class, message);
    }

}
